﻿<#-- 
 
 Author : Luis Molina...
 
 -->
<#-- variables used internally by the generator... -->
<#assign nameFile="${table}">
<#assign extensionFile="cs">
<#assign languageGenerated="c#">
<#assign description="c#">
<#assign targetDirectory="">
<#assign appliesToAllTables="true">
<#-- END variables used internally by the generator... -->
 
 
    <asp:GridView ID="g${table}" runat="server" Width="100%" AllowPaging="True" DataKeyNames="${table.getKey()}"
                            AutoGenerateColumns="False" OnRowDataBound="g${table}_RowDataBound" OnRowCommand="g${table}_RowCommand" OnRowEditing="g${table}_RowEditing">
                            <Columns>
                                <asp:TemplateField ShowHeader="False">
                                    <ItemTemplate>
                                        <asp:LinkButton ID="lbEdit" runat="server" CausesValidation="false" CommandName="Edit" CommandArgument='<%# Eval("${table.getKey()}") %>' Text="Editar"></asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                
                                <asp:TemplateField ShowHeader="False">
                                    <ItemTemplate>
                                    <asp:Label ID="lab${table.getFieldDescription()}" runat="server" Text='<%# Eval("${table.getFieldDescription()}") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                
                                <asp:TemplateField ShowHeader="False">
                                    <ItemTemplate>
                                        <asp:LinkButton ID="lbDelete" runat="server" CausesValidation="false" CommandName="Delete" CommandArgument='<%# Eval("${table.getKey()}") %>' Text="Borrar"></asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>                  
 
 
 
 
	 protected void Page_Load(object sender, EventArgs e)
        {
             
            if (!Page.IsPostBack)
            {
                List<${table}> lista = new List<${table}>();
                lista = ${table}.getList();
                g${table}.DataSource = lista;
                g${table}.DataBind();
            }
			 
        }
        protected void btnBuscar_Click(object sender, EventArgs e)
        {
            List<${table}> lista = new List<${table}>();
            lista = ${table}.getListByBusquedaGeneral(txtBusqueda.Text);
            g${table}.DataSource = lista;
            g${table}.DataBind();
        }
		
		protected void g${table}_RowCommand(Object sender, GridViewCommandEventArgs e)
        {

            int id = sf.entero(e.CommandArgument);

            switch (e.CommandName)
            {
                case "Delete":
                    ${table}.Delete(sf.entero(g${table.getKey()}));
                    break;
                case "Edit":
                    Response.Redirect("./main_${table}.aspx?id=" + sf.cadena(${table.getKey()}));
                    break;
            }

        } // g${table}_RowCommand


        protected void g${table}_RowDataBound(Object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                // Display the company name in italics.
                // e.Row.Cells[1].Text = "<i>" + e.Row.Cells[1].Text + "</i>";
                             

            }

        } // g${table}_RowDataBound


        protected void g${table}_RowEditing(Object sender, GridViewEditEventArgs e)
        {
        } // g${table}_RowEditing
	
  
	 

 
 